/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package unisim201401;

import cfg.cfgNode;
import cfg.cfgParser;
import cfg.cfgType;
import cfg.nodeType;
import datamanager.fieldParser;
import datamanager.fieldType;
import datamanager.scenarioMaker;
import globalutils.LineModeEnum;
import iso8583.IsoMessage;
import iso8583.IsoMessagePipeline;
import iss.issEnum;
import iss.issSettings;
import iss.showLogEnum;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import lib.CommonLib;
import lib.DateUtils;
import lib.msgSecurityEnum;
import lib.secObjInfo;

/**
 *
 * @author netone
 */
public class MainForm extends javax.swing.JFrame {

    /**
     * Creates new form MainForm
     */
    public MainForm() {
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        popmnuReloadCfg = new javax.swing.JPopupMenu();
        popupmnuShowCfg = new javax.swing.JPopupMenu();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cmbACQ = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        cmbCards = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        pnFields1 = new javax.swing.JPanel();
        pnFields2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lstReversal = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        btSendPattern = new javax.swing.JButton();
        btREVSend = new javax.swing.JButton();
        cmbType = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        rtRCAuto = new javax.swing.JRadioButton();
        rtRCManual = new javax.swing.JRadioButton();
        txtRCManual = new javax.swing.JTextField();
        chkMAC = new javax.swing.JCheckBox();
        jPanel5 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        rtAuthNone = new javax.swing.JRadioButton();
        rtAuthAuto = new javax.swing.JRadioButton();
        rtAuthManual = new javax.swing.JRadioButton();
        txtAuthCode = new javax.swing.JTextField();
        btSet = new javax.swing.JButton();
        jPanel8 = new javax.swing.JPanel();
        rtDelayRes = new javax.swing.JRadioButton();
        txtDelay = new javax.swing.JTextField();
        rtNores = new javax.swing.JRadioButton();
        jPanel6 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        chkSimpleFollow = new javax.swing.JCheckBox();
        chkCnns = new javax.swing.JCheckBox();
        chkDetails = new javax.swing.JCheckBox();
        btClearReversal = new javax.swing.JButton();
        btReloadCfg = new javax.swing.JButton();
        btResetCnn = new javax.swing.JButton();
        btResetHsm = new javax.swing.JButton();
        chkReversal = new javax.swing.JCheckBox();
        txtReversal = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        btSimSet = new javax.swing.JButton();
        btSaveIssCfg = new javax.swing.JButton();
        btShowCfg = new javax.swing.JButton();
        btClearLogs = new javax.swing.JButton();
        btHsmTools = new javax.swing.JButton();
        btFlushData = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        cbFontSize = new javax.swing.JComboBox();
        btFontSet = new javax.swing.JButton();
        cmbTransType = new javax.swing.JComboBox();
        chkScope = new javax.swing.JCheckBox();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtOutput = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setPreferredSize(new java.awt.Dimension(862, 400));

        jLabel1.setText("ACQ Profile:");

        cmbACQ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbACQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbACQActionPerformed(evt);
            }
        });

        jLabel3.setText("Card Pan:");

        cmbCards.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel4.setText("Msg Type: ");

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout pnFields1Layout = new javax.swing.GroupLayout(pnFields1);
        pnFields1.setLayout(pnFields1Layout);
        pnFields1Layout.setHorizontalGroup(
            pnFields1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        pnFields1Layout.setVerticalGroup(
            pnFields1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 258, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout pnFields2Layout = new javax.swing.GroupLayout(pnFields2);
        pnFields2.setLayout(pnFields2Layout);
        pnFields2Layout.setHorizontalGroup(
            pnFields2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 154, Short.MAX_VALUE)
        );
        pnFields2Layout.setVerticalGroup(
            pnFields2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jScrollPane3.setViewportView(lstReversal);

        jLabel2.setText("Reversal: ID|Institution|PAN|TRACE|DATE");

        btSendPattern.setText("SEND");
        btSendPattern.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSendPatternActionPerformed(evt);
            }
        });

        btREVSend.setText("SEND");
        btREVSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btREVSendActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(pnFields1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(pnFields2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12))
                    .addComponent(btSendPattern, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btREVSend, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(pnFields1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(pnFields2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btREVSend)
                    .addComponent(btSendPattern))
                .addContainerGap())
        );

        cmbType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTypeActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("ISS Config Zone");

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel4.setToolTipText("");
        jPanel4.setName(""); // NOI18N

        jLabel7.setText("Finacial Response:");

        buttonGroup1.add(rtRCAuto);
        rtRCAuto.setSelected(true);
        rtRCAuto.setText("Auto Response");

        buttonGroup1.add(rtRCManual);
        rtRCManual.setText("Fixed RC");

        txtRCManual.setText("00");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(rtRCAuto)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(rtRCManual)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtRCManual, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rtRCAuto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rtRCManual)
                    .addComponent(txtRCManual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        chkMAC.setSelected(true);
        chkMAC.setText("Don't check MAC");

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel5.setName(""); // NOI18N

        jLabel8.setText("Authorized Response:");

        buttonGroup2.add(rtAuthNone);
        rtAuthNone.setSelected(true);
        rtAuthNone.setText("No authorized Code");

        buttonGroup2.add(rtAuthAuto);
        rtAuthAuto.setText("Auto");

        buttonGroup2.add(rtAuthManual);
        rtAuthManual.setText("Fixxed");

        txtAuthCode.setText("0000");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(rtAuthManual)
                        .addGap(18, 18, 18)
                        .addComponent(txtAuthCode, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(rtAuthAuto)
                    .addComponent(rtAuthNone))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rtAuthNone)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rtAuthAuto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rtAuthManual)
                    .addComponent(txtAuthCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 5, Short.MAX_VALUE))
        );

        btSet.setText("Set");
        btSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSetActionPerformed(evt);
            }
        });

        jPanel8.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        buttonGroup3.add(rtDelayRes);
        rtDelayRes.setSelected(true);
        rtDelayRes.setText("Delay response");

        txtDelay.setText("1");

        buttonGroup3.add(rtNores);
        rtNores.setText("No response");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(rtDelayRes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtDelay))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(rtNores)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rtDelayRes)
                    .addComponent(txtDelay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rtNores)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(chkMAC)
                        .addGap(55, 55, 55))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(btSet, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkMAC)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btSet)
                .addContainerGap())
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel6.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel7.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel9.setText("Show info:");

        chkSimpleFollow.setSelected(true);
        chkSimpleFollow.setText("Show only parsing, send and receive");

        chkCnns.setText("Show connection status");

        chkDetails.setText("Show all in details");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(chkSimpleFollow)
                    .addComponent(chkCnns)
                    .addComponent(chkDetails))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chkSimpleFollow)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkCnns)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 5, Short.MAX_VALUE)
                .addComponent(chkDetails)
                .addContainerGap())
        );

        jPanel6.add(jPanel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(22, 2, 360, -1));

        btClearReversal.setText("Clear Reversal");
        btClearReversal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btClearReversalActionPerformed(evt);
            }
        });
        jPanel6.add(btClearReversal, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 148, 130, -1));

        btReloadCfg.setText("Reload config");
        btReloadCfg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btReloadCfgActionPerformed(evt);
            }
        });
        jPanel6.add(btReloadCfg, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 175, 130, -1));

        btResetCnn.setText("Reset Cnns");
        jPanel6.add(btResetCnn, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 148, 115, -1));

        btResetHsm.setText("Reset HSM");
        jPanel6.add(btResetHsm, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 175, 115, -1));

        chkReversal.setText("Auto send reversal after");
        jPanel6.add(chkReversal, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 120, -1, -1));

        txtReversal.setText("100");
        jPanel6.add(txtReversal, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 120, 68, -1));

        jLabel10.setText("milisec");
        jPanel6.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 120, -1, -1));

        btSimSet.setText("SET");
        btSimSet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSimSetActionPerformed(evt);
            }
        });
        jPanel6.add(btSimSet, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 290, 87, -1));

        btSaveIssCfg.setText("Save ISS config");
        btSaveIssCfg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSaveIssCfgActionPerformed(evt);
            }
        });
        jPanel6.add(btSaveIssCfg, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 148, 120, -1));

        btShowCfg.setText("Show config");
        btShowCfg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btShowCfgActionPerformed(evt);
            }
        });
        jPanel6.add(btShowCfg, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 175, 120, -1));

        btClearLogs.setText("Clear logs");
        btClearLogs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btClearLogsActionPerformed(evt);
            }
        });
        jPanel6.add(btClearLogs, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 205, 130, -1));

        btHsmTools.setText("Tools HSM");
        jPanel6.add(btHsmTools, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 205, 115, -1));

        btFlushData.setText("Flush data");
        jPanel6.add(btFlushData, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 205, 120, -1));

        jLabel6.setText("Font Log size: ");
        jPanel6.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 240, -1, -1));

        cbFontSize.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10", "11", "12", "13", "14", "15" }));
        jPanel6.add(cbFontSize, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 240, -1, -1));

        btFontSet.setText("Set");
        jPanel6.add(btFontSet, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 240, -1, -1));

        cmbTransType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "FINACIAL", "NETWORK", "SCENARIO" }));
        cmbTransType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTransTypeActionPerformed(evt);
            }
        });

        chkScope.setText("Load all in scope");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cmbType, javax.swing.GroupLayout.PREFERRED_SIZE, 406, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cmbCards, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(cmbACQ, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(56, 56, 56)
                                .addComponent(cmbTransType, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(chkScope, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cmbACQ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbTransType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chkScope))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cmbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cmbCards, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        txtOutput.setBackground(new java.awt.Color(0, 0, 0));
        txtOutput.setColumns(20);
        txtOutput.setFont(new java.awt.Font("Courier New", 0, 11)); // NOI18N
        txtOutput.setForeground(new java.awt.Color(255, 255, 255));
        txtOutput.setRows(5);
        txtOutput.setTabSize(4);
        txtOutput.setMargin(new java.awt.Insets(10, 5, 10, 5));
        jScrollPane4.setViewportView(txtOutput);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 614, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 727, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbACQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbACQActionPerformed
        // TODO add your handling code here:
        reloadTransactionAndCards();

    }//GEN-LAST:event_cmbACQActionPerformed

    private void reloadTransactionAndCards() {
        DefaultComboBoxModel theModel;
        theModel = (DefaultComboBoxModel) cmbType.getModel();
        theModel.removeAllElements();
        theModel = (DefaultComboBoxModel) cmbCards.getModel();
        theModel.removeAllElements();
        if (cmbACQ.getSelectedItem() != null) {

            String scope = systemData.getScopeByInstName(cmbACQ.getSelectedItem().toString());
            List<String> allType = systemData.getPatternObj().getAllTransactionType(nodeType.valueOf(cmbTransType.getSelectedItem().toString()), cmbACQ.getSelectedItem().toString() , scope, chkScope.isSelected());
            String[] TypeArray = new String[allType.size()];
            allType.toArray(TypeArray);
            cmbType.setModel(new DefaultComboBoxModel(TypeArray));

            List<String> cardList = systemData.getPatternObj().getAllCards((cmbACQ.getSelectedItem() != null) ? scope : "");
            String[] cardsArray = new String[cardList.size()];
            cardList.toArray(cardsArray);
            cmbCards.setModel(new DefaultComboBoxModel(cardsArray));
        }
    }

    private void cmbTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTypeActionPerformed
        // TODO add your handling code here:
        if (cmbType.getSelectedItem() != null) {
            String instCmb = cmbType.getSelectedItem().toString();
            String msgCode = instCmb.substring(0, instCmb.indexOf("("));
            String xmlFile = instCmb.substring(instCmb.indexOf("(") + 1, instCmb.length() - 1);
            cfgNode tmpNode = systemData.getPatternObj().getTempNode(xmlFile, msgCode);
            buildCustomControl(tmpNode);
        }
    }//GEN-LAST:event_cmbTypeActionPerformed

    private void btSendPatternActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSendPatternActionPerformed
        // TODO add your handling code here:
        switch (nodeType.valueOf(cmbTransType.getSelectedItem().toString())) {
            case SCENARIO:
                String instCmb = cmbType.getSelectedItem().toString();
                String msgCode = instCmb.substring(0, instCmb.indexOf("("));
                String xmlFile = instCmb.substring(instCmb.indexOf("(") + 1, instCmb.length() - 1);
                cfgParser scenarioFile = systemData.getPatternObj().getFileParserByName(xmlFile);
                scenarioMaker makeMessage = new scenarioMaker(scenarioFile);
                makeMessage.setDesInstitution(cmbACQ.getSelectedItem().toString());
                makeMessage.setIsoCfg(systemData.getIsoFormatByScope(systemData.getInstitutionDataConfig(cmbACQ.getSelectedItem().toString()).getValue("SCOPE")));
                makeMessage.buildMessages();
                List<IsoMessage> msgRs = makeMessage.getListOfMsg();
                for (IsoMessage imsg : msgRs) {
                    CommonLib.PrintScreen(systemData, imsg.printedMessage(), showLogEnum.DEFAULT);
                    imsg.setSecRequest(systemData.getINFSecurityUtils(imsg.getDesInterfaceCode()));
                    imsg.setLineMode(LineModeEnum.valueOf(systemData.getInstitutionDataConfig(cmbACQ.getSelectedItem().toString()).getValue("LINEMODE")));
                    imsg.setMsgType(CommonLib.getMsgType(imsg.getField(0)));
                    if (imsg.getDelaytime() >= 0) {
                        systemData.getDelayQueue().addMessage(imsg, imsg.getDelaytime());
                    } else {
                        systemData.getIcmQueue().add(imsg);
                    }
                }
                break;
            default:
            case FINACIAL:
                IsoMessage buildMessage = new IsoMessage();
                buildMessage.setIsoCfg(systemData.getIsoFormatByScope(systemData.getInstitutionDataConfig(cmbACQ.getSelectedItem().toString()).getValue("SCOPE")));
                buildMessage.setLineMode(LineModeEnum.valueOf(systemData.getInstitutionDataConfig(cmbACQ.getSelectedItem().toString()).getValue("LINEMODE")));

                buildMessage.setSourceInterfaceCode("SIMUI");
                if (cmbType.getSelectedItem() != null) {

                    instCmb = cmbType.getSelectedItem().toString();
                    msgCode = instCmb.substring(0, instCmb.indexOf("("));
                    xmlFile = instCmb.substring(instCmb.indexOf("(") + 1, instCmb.length() - 1);
                    cfgNode tmpNode = systemData.getPatternObj().getTempNode(xmlFile, msgCode);

                    Map<String, fieldParser> controlFieldPatterns = tmpNode.getFieldPatternFromNode();
                    //buildMessage.setDesInterfaceCode(tmpNode.getNodeAtt("des"));
                    System.out.println(controlFieldPatterns.keySet());
                    for (Entry<String, fieldParser> entry : controlFieldPatterns.entrySet()) {
                        String key = entry.getKey();
                        fieldParser value = entry.getValue();

                        switch (value.getType()) {
                            case MANUAL:
                                JTextField txtManual = mappingMNField.get(key);
                                buildMessage.setField(CommonLib.valueOf(key), txtManual.getText());

                                break;
                            case MANUAL_HSM:
                                secObjInfo pinCmdReq = new secObjInfo(msgSecurityEnum.IN_NEED_GEN_PIN);
                                if (key.equals("52")) {
                                    pinCmdReq.setFields(new String[]{"52"});

                                } else {
                                    pinCmdReq.setFields(new String[]{"48"});
                                }
                                pinCmdReq.setHsmCommnadID(CommonLib.getHSMCommandID());
                                pinCmdReq.setMsgID(buildMessage.getSeqID());
                                pinCmdReq.setsZone(buildMessage.getSourceInterfaceCode());
                                pinCmdReq.setdZone(buildMessage.getDesInterfaceCode());
                                txtManual = mappingMNField.get(key);
                                buildMessage.setField(CommonLib.valueOf(key), txtManual.getText());
                                buildMessage.addSecRequest(pinCmdReq);
                                break;
                            case AUTO_DATE:
                                buildMessage.setField(CommonLib.valueOf(key), DateUtils.getCurrentDateIST());
                                break;
                            case AUTO_DATETIME:
                                buildMessage.setField(CommonLib.valueOf(key), DateUtils.getCurrentDateTime());
                                break;
                            case AUTO_PAN:
                                String track2 = cmbCards.getSelectedItem().toString();
                                buildMessage.setField(CommonLib.valueOf(key), track2.substring(0, track2.indexOf("=")));
                                break;
                            case AUTO_TRACK2:
                                track2 = cmbCards.getSelectedItem().toString();
                                buildMessage.setField(CommonLib.valueOf(key), track2);
                                break;
                            case AUTO_TIME:
                                buildMessage.setField(CommonLib.valueOf(key), DateUtils.getTime());
                                break;
                            case AUTO_SEQ37:
                                buildMessage.setField(CommonLib.valueOf(key), CommonLib.getRefNo());
                                break;
                            case AUTO_TRACE:
                                buildMessage.setField(CommonLib.valueOf(key), CommonLib.getSystemTrace());
                                break;
                            case AUTO_AMMOUNT:
                                String[] amms = value.getFieldValue().split("-");
                                int minAmm = CommonLib.valueOf(amms[0]);
                                int maxAmm = CommonLib.valueOf(amms[1]);
                                int digit = CommonLib.valueOf(amms[2]);
                                buildMessage.setField(CommonLib.valueOf(key), CommonLib.getAmmount(minAmm, maxAmm, digit, 12));
                            case AUTO_BITMAP:
                                break;
                            case AUTO_ZPK:
                                pinCmdReq = new secObjInfo(msgSecurityEnum.NET_ZPK_GENERATE_ZMK);

                                pinCmdReq.setHsmCommnadID(CommonLib.getHSMCommandID());
                                pinCmdReq.setMsgID(buildMessage.getSeqID());
                                pinCmdReq.setsZone(buildMessage.getSourceInterfaceCode());
                                pinCmdReq.setdZone(buildMessage.getDesInterfaceCode());
                                buildMessage.addSecRequest(pinCmdReq);
                                break;
                            case AUTO_MAC_GEN:
                                pinCmdReq = new secObjInfo(msgSecurityEnum.IN_NEED_OF_MACGEN);
                                if (key.equals("64")) {
                                    pinCmdReq.setFields(new String[]{"64"});

                                } else {
                                    pinCmdReq.setFields(new String[]{"128"});
                                }
                                pinCmdReq.setHsmCommnadID(CommonLib.getHSMCommandID());
                                pinCmdReq.setMsgID(buildMessage.getSeqID());
                                pinCmdReq.setsZone(buildMessage.getSourceInterfaceCode());
                                pinCmdReq.setdZone(buildMessage.getDesInterfaceCode());
                                buildMessage.addSecRequest(pinCmdReq);
                                break;
                            default:
                                buildMessage.setField(CommonLib.valueOf(key), value.getFieldValue());
                        }
                    }
                    buildMessage.setMessageState(true);
                    buildMessage.setMsgType(CommonLib.getMsgType(buildMessage.getField(0)));
                    buildMessage.setDesInterfaceCode(cmbACQ.getSelectedItem().toString());
                    systemData.getIcmQueue().add(buildMessage);
                    txtOutput.setText(txtOutput.getText() + "\n\r" + new String(buildMessage.toByte()));
                    if (nodeType.valueOf(cmbTransType.getSelectedItem().toString()) == nodeType.REVERSAL) {
                        cfgNode revFmt = systemData.getPatternObj().getTempNode(xmlFile, tmpNode.getNodeAtt("rev"));
                        IsoMessage revMsg = systemData.getIssResponse(cmbACQ.getSelectedItem().toString()).makeRevFromFin(buildMessage, revFmt);
                        revMsg.setLineMode(LineModeEnum.valueOf(systemData.getInstitutionDataConfig(cmbACQ.getSelectedItem().toString()).getValue("LINEMODE")));
                        revMsg.setMsgType(CommonLib.getMsgType(revMsg.getField(0)));
                        if (chkReversal.isSelected()) {

                            revMsg.setDelaytime(CommonLib.valueOf(txtReversal.getText()));
                            systemData.getDelayQueue().addMessage(revMsg, revMsg.getDelaytime());
                            //systemData.getIcmQueue().add(revMsg);

                            txtOutput.setText(txtOutput.getText() + "\n\r" + new String(revMsg.toByte()));

                        } else {
                            systemData.getReversalMap().add(revMsg.getSeqID(), revMsg);
                            updateListReversal();
                        }
                    }

                }

        }

    }//GEN-LAST:event_btSendPatternActionPerformed

    private void updateListReversal() {
        List<String> revMsgInfo = systemData.getReversalMap().getMsgInfo();
        Collections.reverse(revMsgInfo);
        DefaultListModel listRevModel = new DefaultListModel();
        //DefaultListModel listRevModel = (DefaultListModel) lstReversal.getModel();
        listRevModel.removeAllElements();
        for (String iRow : revMsgInfo) {
            listRevModel.addElement(iRow);
        }
        lstReversal.setModel(listRevModel);
    }

    private void btSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSetActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:

        if (rtRCManual.isSelected()) {
            issResponseCfg.getRc().setType(issEnum.FIXXED);
            issResponseCfg.getRc().setValueForFix(txtRCManual.getText());
        } else {
            issResponseCfg.getRc().setType(issEnum.AUTO);
            issResponseCfg.getRc().setValueForFix("");
        }
        if (rtAuthAuto.isSelected()) {
            issResponseCfg.getAuth().setType(issEnum.AUTO);
            issResponseCfg.getAuth().setValueForFix("");
        }
        if (rtAuthNone.isSelected()) {
            issResponseCfg.getAuth().setType(issEnum.NONE);
            issResponseCfg.getAuth().setValueForFix("");
        }
        if (rtAuthManual.isSelected()) {
            issResponseCfg.getAuth().setType(issEnum.NONE);
            issResponseCfg.getAuth().setValueForFix(txtAuthCode.getText());
        }
        if (rtDelayRes.isSelected()) {
            issResponseCfg.setDelayTime(CommonLib.valueOf(txtDelay.getText()));
            issResponseCfg.setDelayResponse(true);
        } else {
            issResponseCfg.setDelayResponse(false);
            issResponseCfg.setDelayTime(0);
        }
        if (rtNores.isSelected()) {
            issResponseCfg.setDelayResponse(true);
            issResponseCfg.setDelayTime(-1);
        }
        issResponseCfg.setRequireMac(chkMAC.isSelected());

        systemData.setIssCfg(issResponseCfg);
    }//GEN-LAST:event_btSetActionPerformed

    private void btSimSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSimSetActionPerformed
        // TODO add your handling code here:
        systemData.getsParas().setIsShowSimpleLogs(chkSimpleFollow.isSelected());
        systemData.getsParas().setIsShowCnns(chkCnns.isSelected());
        systemData.getsParas().setIsShowDetails(chkDetails.isSelected());
        systemData.getsParas().setIsSendReversal(chkReversal.isSelected());
        systemData.getsParas().setSendRevTime(CommonLib.valueOf(txtReversal.getText()));
    }//GEN-LAST:event_btSimSetActionPerformed

    private void cmbTransTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTransTypeActionPerformed
        // TODO add your handling code here:
        reloadTransactionAndCards();
    }//GEN-LAST:event_cmbTransTypeActionPerformed

    private void btREVSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btREVSendActionPerformed
        // TODO add your handling code here:
        List<String> revMsgStringList = lstReversal.getSelectedValuesList();
        if (revMsgStringList != null) {
            for (String selRow : revMsgStringList) {
                String[] revMsgId = selRow.split("\\|");

                IsoMessage revMsg = (IsoMessage) systemData.getReversalMap().peek(CommonLib.valueOf(revMsgId[0]));
                if (revMsg != null) {
                    systemData.getIcmQueue().add(revMsg);
                }
            }
            updateListReversal();
        }
    }//GEN-LAST:event_btREVSendActionPerformed

    private void btSaveIssCfgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSaveIssCfgActionPerformed
        // TODO add your handling code here:
        cfgParser[] issCfgData = systemData.getIssCardData().toArray();
        for (cfgParser cfg : issCfgData) {
            cfg.saveCfg(cfg.getABsolutePath());
        }

    }//GEN-LAST:event_btSaveIssCfgActionPerformed

    private void btClearReversalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClearReversalActionPerformed
        // TODO add your handling code here:
        systemData.getReversalMap().clear();
        updateListReversal();
    }//GEN-LAST:event_btClearReversalActionPerformed

    private void btClearLogsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClearLogsActionPerformed
        // TODO add your handling code here:
        txtOutput.setText("");
    }//GEN-LAST:event_btClearLogsActionPerformed

    private void btReloadCfgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btReloadCfgActionPerformed
        // TODO add your handling code here:
        //systemData.reloadCFG();
        popmnuReloadCfg.show(btReloadCfg, btReloadCfg.getWidth() - 15, btReloadCfg.getHeight() - 5);
    }//GEN-LAST:event_btReloadCfgActionPerformed

    private void btShowCfgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btShowCfgActionPerformed
        // TODO add your handling code here:
        popupmnuShowCfg.show(btShowCfg, btShowCfg.getWidth() - 15, btShowCfg.getHeight() - 5);
    }//GEN-LAST:event_btShowCfgActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainForm().setVisible(true);
            }
        });
    }

    public void setSystemData(systemLoader systemData) {
        this.systemData = systemData;
        this.systemData.setTaLogs(txtOutput);
        cfgParser systemCFG = systemData.getSystemConfig();
        cfgNode instNode = systemCFG.getXmlNode("BANK-PROFILE");
        List<String> allInsts = instNode.getFieldKeys();

        List<String> instName = new LinkedList<>();
        String[] InsArray = new String[allInsts.size()];
        for (String nodeValue : instNode.getFieldKeys()) {
            cfgParser cfgInst = systemData.getCfgInstByFileName(instNode.getValue(nodeValue));
            if (cfgInst != null) {
                instName.add(cfgInst.getValue("INSTITUTION", "INTERFACECODE"));
            }
        }
        instName.toArray(InsArray);
        //allInsts.toArray(InsArray);

        DefaultComboBoxModel theModel = (DefaultComboBoxModel) cmbACQ.getModel();
        theModel.removeAllElements();

        cmbACQ.setModel(new DefaultComboBoxModel(InsArray));

        txtOutput.setLineWrap(true);
        /*theModel = (DefaultComboBoxModel) cmbCards.getModel();
         theModel.removeAllElements();
         List<String> cardList = systemData.getPatternObj().getAllCards("IST");
         String[] cardsArray = new String[cardList.size()];
         cardList.toArray(cardsArray);
         cmbCards.setModel(new DefaultComboBoxModel(cardsArray));*/
        pack();
        initPopupmnuReload();
        initPopupmnuShowcfg();
        //getContentPane().add(cmbACQ, BorderLayout.SOUTH);
        //http://www.coderanch.com/t/529195/GUI/java/set-ID-JCombobox
    }

    private String getScopeByInstitution(String pInstitution) {

        return systemData.getScopeByInstName(pInstitution);

    }

    private void buildCustomControl(cfgNode nodeNeedToBuild) {
        if (mappingMNField != null) {
            mappingMNField.clear();
        }
        if (lblFields != null) {
            int iControl = 0;
            for (iControl = 0; iControl < lblFields.length; iControl++) {
                lblFields[iControl].setVisible(false);

                lblFields[iControl] = null;

                txtFields[iControl].setVisible(false);

                txtFields[iControl] = null;

            }
            lblFields = null;
            txtFields = null;
        }

        pnFields1.removeAll();
        pnFields2.removeAll();
        Vector<fieldType> filterFields = new Vector<>();
        filterFields.add(fieldType.MANUAL);
        filterFields.add(fieldType.MANUAL_HSM);
        HashMap<String, fieldParser> controlFieldPatterns = nodeNeedToBuild.getFieldPatternFromNode(filterFields);
        pnFields1.setLayout(new GridLayout(12, 1));
        //pnFields1.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 2));
        pnFields1.setPreferredSize(new Dimension(110, 258));
        pnFields2.setPreferredSize(new Dimension(160, 258));
        pnFields2.setLayout(new GridLayout(12, 1));
        lblFields = new javax.swing.JLabel[controlFieldPatterns.size()];
        txtFields = new javax.swing.JTextField[controlFieldPatterns.size()];
        mappingMNField = new HashMap<>();
        int iField = 0;
        for (Entry<String, fieldParser> entry : controlFieldPatterns.entrySet()) {
            String key = entry.getKey();
            fieldParser value = entry.getValue();
            lblFields[iField] = new javax.swing.JLabel();
            lblFields[iField].setText("Field " + key);
            txtFields[iField] = new JTextField(15);
            txtFields[iField].setText(value.getFieldValue());
            pnFields1.add(lblFields[iField]);
            pnFields2.add(txtFields[iField]);
            mappingMNField.put(key, txtFields[iField]);
            iField++;
            // do what you have to do here
            // In your case, an other loop.
        }
        pnFields1.revalidate();
    }
    private issSettings issResponseCfg = new issSettings();
    private systemLoader systemData;
    private javax.swing.JLabel lblFields[];
    private javax.swing.JTextField txtFields[];
    private HashMap<String, JTextField> mappingMNField;

    private void initPopupmnuReload() {
        JMenuItem menuRouting = new JMenuItem("Routing config");
        menuRouting.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuReloadCfg", cfgType.ROUTING_TABLE));
        JMenuItem menuCardData = new JMenuItem("Card data");
        menuCardData.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuReloadCfg", cfgType.CARD));
        JMenuItem menuIssResp = new JMenuItem("Iss response fmt");
        menuIssResp.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuReloadCfg", cfgType.ISS_RESPONSE));
        JMenuItem menuInstCfg = new JMenuItem("Institution Cfg");
        menuInstCfg.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuReloadCfg", cfgType.BANK));

        JMenuItem menupatternCfg = new JMenuItem("Pattern Cfg");
        menupatternCfg.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuReloadCfg", cfgType.PATTRENDATA));

        JMenuItem menuAllCfg = new JMenuItem("All cfg");
        menuAllCfg.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuReloadCfg", cfgType.UNKNOWN));
        // Create a popup menu
        popmnuReloadCfg.add(menuRouting);
        popmnuReloadCfg.add(menuCardData);
        popmnuReloadCfg.add(menuIssResp);
        popmnuReloadCfg.add(menuInstCfg);
        popmnuReloadCfg.add(menupatternCfg);
        popmnuReloadCfg.addSeparator();
        popmnuReloadCfg.add(menuAllCfg);
    }

    private void initPopupmnuShowcfg() {
        JMenuItem menusystem = new JMenuItem("System config");
        menusystem.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuShowCfg", cfgType.SYSTEM));

        JMenuItem menuRouting = new JMenuItem("Routing config");
        menuRouting.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuShowCfg", cfgType.ROUTING_TABLE));

        JMenuItem menuCardData = new JMenuItem("Card data");
        menuCardData.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuShowCfg", cfgType.CARD));

        JMenuItem menuIssResp = new JMenuItem("Iss response fmt");
        menuIssResp.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuShowCfg", cfgType.ISS_RESPONSE));

        JMenuItem menuInstCfg = new JMenuItem("Institution Cfg");
        menuInstCfg.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuShowCfg", cfgType.BANK));

        JMenuItem menupatternCfg = new JMenuItem("Pattern Cfg");
        menupatternCfg.addActionListener(ListenerProxies.actionListener(this, "processPopupMnuShowCfg", cfgType.PATTRENDATA));

        // Create a popup menu
        popupmnuShowCfg.add(menusystem);
        popupmnuShowCfg.add(menuRouting);
        popupmnuShowCfg.addSeparator();
        popupmnuShowCfg.add(menuCardData);
        popupmnuShowCfg.add(menuIssResp);
        popupmnuShowCfg.add(menuInstCfg);
        popupmnuShowCfg.add(menupatternCfg);

    }

    public void processPopupMnuReloadCfg(ActionEvent event, cfgType typeForReload) {

        systemData.reloadCFG(typeForReload);

    }

    public void processPopupMnuShowCfg(ActionEvent event, cfgType typeForReload) {
        configurationInfo ci = new configurationInfo();
        ci.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        switch (typeForReload) {
            case SYSTEM:
                ci.setListOfCfg(new cfgParser[]{systemData.getSystemConfig()});

                break;
            case ROUTING_TABLE:
                ci.setListOfCfg(new cfgParser[]{systemData.getcfgRouting()});
                break;
            case CARD:
                ci.setListOfCfg(systemData.getIssCardData().toArray());
                break;
            case BANK:
                ci.setListOfCfg(systemData.getInstArray());
                break;
            case ISS_RESPONSE:
                ci.setListOfCfg(systemData.getIssResformat().toArray());
                break;
            case PATTRENDATA:
                ci.setListOfCfg(systemData.getPatternObj().toArray());
                break;
        }
        ci.initCfgShow();
        ci.setVisible(true);
        //systemData.reloadCFG(typeForReload);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btClearLogs;
    private javax.swing.JButton btClearReversal;
    private javax.swing.JButton btFlushData;
    private javax.swing.JButton btFontSet;
    private javax.swing.JButton btHsmTools;
    private javax.swing.JButton btREVSend;
    private javax.swing.JButton btReloadCfg;
    private javax.swing.JButton btResetCnn;
    private javax.swing.JButton btResetHsm;
    private javax.swing.JButton btSaveIssCfg;
    private javax.swing.JButton btSendPattern;
    private javax.swing.JButton btSet;
    private javax.swing.JButton btShowCfg;
    private javax.swing.JButton btSimSet;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JComboBox cbFontSize;
    private javax.swing.JCheckBox chkCnns;
    private javax.swing.JCheckBox chkDetails;
    private javax.swing.JCheckBox chkMAC;
    private javax.swing.JCheckBox chkReversal;
    private javax.swing.JCheckBox chkScope;
    private javax.swing.JCheckBox chkSimpleFollow;
    private javax.swing.JComboBox cmbACQ;
    private javax.swing.JComboBox cmbCards;
    private javax.swing.JComboBox cmbTransType;
    private javax.swing.JComboBox cmbType;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JList lstReversal;
    private javax.swing.JPanel pnFields1;
    private javax.swing.JPanel pnFields2;
    private javax.swing.JPopupMenu popmnuReloadCfg;
    private javax.swing.JPopupMenu popupmnuShowCfg;
    private javax.swing.JRadioButton rtAuthAuto;
    private javax.swing.JRadioButton rtAuthManual;
    private javax.swing.JRadioButton rtAuthNone;
    private javax.swing.JRadioButton rtDelayRes;
    private javax.swing.JRadioButton rtNores;
    private javax.swing.JRadioButton rtRCAuto;
    private javax.swing.JRadioButton rtRCManual;
    private javax.swing.JTextField txtAuthCode;
    private javax.swing.JTextField txtDelay;
    private javax.swing.JTextArea txtOutput;
    private javax.swing.JTextField txtRCManual;
    private javax.swing.JTextField txtReversal;
    // End of variables declaration//GEN-END:variables
}
